package com.beasu.tingting.utils

import androidx.lifecycle.MutableLiveData


class Wave {

          val  HIGHT = 32767
          val  TWOPI = 2*Math.PI
         val 采样频率 =  44100

        fun sin(fre: Int, time: Int):ShortArray {
            val 持续时间 = 1.0 * time / 1000

            val 步进 = TWOPI * fre / 采样频率
            val times = 1.0 * 采样频率 / fre
            val 总采点数 = (fre * 持续时间 * times).toInt()
            var wave = ShortArray(总采点数)
            var t: Double = 0.0
            for (i in 0 until 总采点数) {
                wave[i] = ((HIGHT * kotlin.math.sin(t)).toShort())
                t += 步进
            }

            return wave
        }
    }
